package LabPrueba;
import java.awt.Component; 
import java.awt.Color; 
import javax.swing.JTable; 
import javax.swing.table. DefaultTableCellRenderer; 
import javax.swing.*; 

public class MiRender extends DefaultTableCellRenderer { 

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 
			Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 
			//se centran los valores 
			if (column == 2 ||column == 4 || column == 5 || column == 6 || column == 7){ 
				this.setHorizontalAlignment(SwingConstants.CENTER); 
			} else { 
				this.setHorizontalAlignment(SwingConstants.LEFT); 
			} 
			//se toman algunos valores especificos para mi programa 
			int cantidad = Integer.parseInt(table.getValueAt(row, 4).toString()); 
			int stockMin = Integer.parseInt(table.getValueAt(row, 5).toString()); 
			int stockMax = Integer.parseInt(table.getValueAt(row, 6).toString()); 
			//si cumplen x condicion se pintan 
			if (cantidad < stockMin){ 
				cell.setBackground(Color.RED); 
				cell.setForeground(Color.WHITE); 
			} 
			if (cantidad > stockMax){ 
				cell.setBackground(Color.YELLOW); 
				cell.setForeground(Color.BLACK); 
			} 
			//si no cumplen esa condicion pongo las celdas en color blanco 
			if ((cantidad >= stockMin) && (cantidad <= stockMax)){ 
				cell.setBackground(Color.WHITE); 
				cell.setForeground(Color.BLACK); 
			} 
			return cell; 
	} 
} 
